<?
session_start();
include('../admin/bd.php');
Conectar();
// recupero datos
$_SESSION[nombre_d]=$_POST[nombre];
$_SESSION[apellido_d]=$_POST[apellido];
$_SESSION[address_1_d]=$_POST[address_1];
$_SESSION[address_2_d]=$_POST[address_2];
$_SESSION[city_d]=$_POST[city];
$_SESSION[state_d]=$_POST[state];
$_SESSION[phone_d]=$_POST[phone];
$_SESSION[alt_phone_d]=$_POST[alt_phone];
$_SESSION[email_d]=$_POST[email];
$_SESSION[envio_met_d]=$_POST[envio];
$_SESSION[ok]='yes';

// busco codigo de estado
$res_code=mysql_query("SELECT StateAbrv, State, DefaultZipCode FROM tbl_states WHERE State='".$_POST[state]."'");
while($row_code = mysql_fetch_array($res_code, MYSQL_ASSOC)){
$_SESSION[state_code_d]=$row_code[StateAbrv];
$_SESSION[zip_d]=$row_code[DefaultZipCode];
}

// calculo costo de evnio. FEDEX
$_SESSION[envio_d]='0';

$_SESSION[envio_code]='';// codigo de envio de FEDEX

// calculo tax
if($_POST[state]=='Texas'){
$total_t_d= substr($_POST[total], 0, strlen($_POST[total]) -2);
$total_t_c= substr($_POST[total], -2, 2);
$_total=$total_t_d.'.'.$total_t_c;
$total_t_tax_porc=(($_total*'8.25')/'100');
// dejo solo dos decimales despues del .
            $dot = (strlen($total_t_tax_porc) - strrpos($total_t_tax_porc, "."))*(-1);
            $file_ext = substr($total_t_tax_porc, $dot);
            $ext = strtolower($file_ext);
			$ext= substr($ext, 0, 3);
			$total_t_tax_porc_f=explode('.', $total_t_tax_porc);
			$tax_=$total_t_tax_porc_f[0].$ext;
$_SESSION[tax_d]=$tax_;
}else{
$_SESSION[tax_d]='';
}
$_total_tax_f=str_replace('.', '', $tax_);
// total final
$_SESSION[total_final_d]=($_total_tax_f+$_SESSION[envio_d]+$_POST[total]);
$_SESSION[impuestos_d]='yes';
header('Location: ../payment_confirm.php');
Desconectar();
?>